Refresher and Functions

Python operators

The following operators can be used to perform basic mathematical calculations in Python

Name Operator
Addition +
Subtraction -
Multiplication *
Division /
Modulus &
Exponentiation **

Essential mathematical functions

Here is a list of the most useful functions available in Python for maths.

To use these make sure you imported the Numpy module:

import numpy as np

Trigonometric functions

Hyperbolic functions

Exponents and logarithms

Drawing functions

You can easily draw functions using the matplotlib module.

So make sure you import the module:

import matplotlib.pyplot as plt  

Here are some essential functions needed to plot a graph:

For example, to plot the function sin(x)^2 with x between -4 and 4, you could write the following code:

import numpy as np 
import matplotlib.pyplot as plt  

# Compute the x and y coordinates for points on curve 
x = np.arange(-4, 4, 0.1) # Generate array of numbers between -4 and 4 with step size of 0.1 for x coordinates
y = np.sin(x)**2
plt.title("sine wave form") 

# Plot the points using matplotlib 
plt.plot(x, y) 
plt.show() 
Try it out